home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _CE158417F56A4F80BD96ED312F902286 < prev    next >
Encoding:
Text File  |  2004-01-06  |  12.7 KB  |  346 lines

  1. ScoreBoardManager =
  2. {
  3.     messages = {},
  4.     visible = 0,
  5.     white_dot=System:LoadImage("Textures/hud/white_dot.tga")
  6. }
  7. -----------------------------------------------------------------------------
  8. function ScoreBoardManager:NewScore(playerid, newscore, newdeaths, newping, readystate)
  9.  
  10.     local idx=getn(self.scores)+1;
  11.     
  12.     self.scores[idx]={
  13.         score=newscore,
  14.         deaths=newdeaths,
  15.         ping=newping,
  16.         ready=readystate,
  17.         id=playerid,
  18.     };
  19. end
  20.  
  21. -----------------------------------------------------------------------------
  22. function ScoreBoardManager.SetVisible(v)
  23.     ScoreBoardManager.visible = v;
  24. end
  25. -----------------------------------------------------------------------------
  26. function ScoreBoardManager.ClearScores()
  27.     ScoreBoardManager.scores = {};
  28.     ScoreBoardManager.teamscores = {};
  29. end
  30.  
  31. -----------------------------------------------------------------------------
  32. --RED/BLUE CLASSIC TEAM GAME 
  33. -----------------------------------------------------------------------------
  34. function player_compare(a,b)
  35.     if(a.kills~=b.kills)then 
  36.         if(a.kills>b.kills)then 
  37.             return 1
  38.         end
  39.     else 
  40.         if(a.entity:GetName()<b.entity:GetName())then 
  41.             return 1
  42.         end 
  43.     end
  44. end
  45.  
  46. -----------------------------------------------------------------------------
  47. function ScoreBoardManager:RenderTeam(team,score,xpos,ypos,xsize,ysize,clr,bspectator, bclass, yScale)
  48.     
  49.     Game:SetHUDFont("default", "scoreboard");
  50.     
  51.     local header_textsize = 15;
  52.     local body_textsize = 13;
  53.     
  54.     local killsfieldsize = Game:GetHudStringSize("KILLS", header_textsize, header_textsize);
  55.     local deathsfieldsize = Game:GetHudStringSize("DEATHS", header_textsize, header_textsize);
  56.     local classfieldsize = Game:GetHudStringSize("CLASS", header_textsize, header_textsize);
  57.     local pingfieldsize = Game:GetHudStringSize("PING", header_textsize, header_textsize);
  58.  
  59.     local tpos=ypos;
  60.     local gamestate=Client:GetGameStateString();
  61.     
  62.     if(not bspectator and score)then
  63.         Game:WriteHudString( xpos+6, tpos-5*yScale, "$1SCORE "..score, 1, 1, 1, 1, header_textsize*1.4*yScale, header_textsize*1.4*yScale);        
  64.         
  65.         tpos=tpos+21*yScale;
  66.         
  67.         local headerScaled=(header_textsize-2)*yScale;
  68.                                 
  69.         if(bclass) then
  70.             Game:WriteHudString( xpos+(xsize-156), tpos+4*yScale, "$1CLASS", 0, 1, 0, 1, headerScaled, headerScaled);
  71.         end
  72.  
  73.         Game:WriteHudString( xpos+(xsize-118), tpos+4*yScale, "$1DEATHS", 0, 1, 0, 1, headerScaled, headerScaled);
  74.         Game:WriteHudString( xpos+(xsize-72), tpos+4*yScale, "$1PING", 0, 1, 0, 1, headerScaled, headerScaled);
  75.         Game:WriteHudString( xpos+(xsize-40), tpos+4*yScale, "$1KILLS", 0, 1, 0, 1, headerScaled, headerScaled);
  76.         
  77.         tpos = tpos + 6*yScale;
  78.                     
  79.         if(count(team)>1)then
  80.             sort(team,%player_compare);
  81.         end    
  82.     end
  83.     tpos = tpos - 6*yScale;
  84.         
  85.     local textsizeScaled=body_textsize*yScale;
  86.     
  87.     for i,val in team do                        
  88.         tpos=tpos+21*yScale;
  89.                         
  90.         if(not bspectator)then
  91.         
  92.             if(val.entity==_localplayer)then
  93.                 if(gamestate=="PREWAR" and val.ready)then
  94.                     Game:WriteHudString( xpos+15+2, tpos+6*yScale, "$6"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  95.                 else
  96.                     Game:WriteHudString( xpos+10+2, tpos+6*yScale, "$6"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  97.                 end            
  98.             else
  99.                 if(gamestate=="PREWAR" and val.ready)then
  100.                     Game:WriteHudString( xpos+15+2, tpos+6*yScale, "$1"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  101.                 else
  102.                     Game:WriteHudString( xpos+10+2, tpos+6*yScale, "$1"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  103.                 end            
  104.             end
  105.                     
  106.             local deathssize = Game:GetHudStringSize(val.deaths, textsizeScaled, textsizeScaled);
  107.             local pingsize = Game:GetHudStringSize(val.ping, textsizeScaled, textsizeScaled);
  108.             local killssize = Game:GetHudStringSize(val.kills, textsizeScaled, textsizeScaled);
  109.             local classsizex = 32;
  110.                 
  111.             local classx = xpos+(xsize-156) + (classfieldsize - classsizex) * 0.5;
  112.             local deathsx = xpos+(xsize-118) + (deathsfieldsize - deathssize) * 0.5;
  113.             local pingx = xpos+(xsize-72) + (pingfieldsize - pingsize) * 0.5;
  114.             local killsx = xpos+(xsize-40) + (killsfieldsize - killssize) * 0.5;
  115.             
  116.             local bs = 32/128;
  117.             local by = 4/128;
  118.  
  119.             if bclass and val.pclass then
  120.                 local textureScaled=20*yScale;
  121.                 if (strupper(val.pclass) == "GRUNT") then
  122.                     System:DrawImageColorCoords(self.iClassTexture, classx, tpos+yScale, textureScaled, textureScaled, 4, 1, 1, 1, 1, 0, 1-by, bs, by);
  123.                 elseif (strupper(val.pclass) == "SUPPORT") then
  124.                     System:DrawImageColorCoords(self.iClassTexture, classx, tpos+yScale, textureScaled, textureScaled, 4, 1, 1, 1, 1, 1-bs, 1-by, 1, by);
  125.                 elseif (strupper(val.pclass) == "SNIPER") then
  126.                     System:DrawImageColorCoords(self.iClassTexture, classx, tpos+yScale, textureScaled, textureScaled, 4, 1, 1, 1, 1, bs+bs, 1-by, bs+bs+bs, by);
  127.                 end    
  128.             end
  129.  
  130.             Game:WriteHudString( deathsx, tpos+6*yScale, "$1"..val.deaths, 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  131.             Game:WriteHudString( pingx, tpos+6*yScale, "$1"..val.ping, 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  132.             Game:WriteHudString( killsx, tpos+6*yScale, "$1"..val.kills, 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  133.             
  134.             if(gamestate=="PREWAR" and val.ready)then
  135.                 Game:WriteHudString( xpos+5, tpos-21*yScale, "$3R", 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  136.             end
  137.         else                            
  138.             Game:WriteHudString( xpos+15+2, tpos, val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);            
  139.             Game:WriteHudString( xpos+(xsize-88), tpos, "$6SPECTATOR", 1, 1, 1, 1, textsizeScaled, textsizeScaled);
  140.         end                
  141.         
  142.     end
  143.     return ysize;
  144. end
  145.  
  146. function ScoreBoardManager:RenderTeamGame(bclass)
  147.     if(self.visible==1)then
  148.         
  149.         local teams={
  150.             blue={},
  151.             red={},
  152.             spectators={}
  153.         }
  154.         local bluescore=Game:GetTeamScore("red");
  155.         local redscore=Game:GetTeamScore("blue");
  156.         for id, val in ScoreBoardManager.scores do
  157.             local ent = System:GetEntity(val.id);
  158.             if ent and ((ent.classname=="Spectator") or (ent.classname=="Player")) then
  159.                 local team=Game:GetEntityTeam(ent.id);
  160.                 if(team)then
  161.                     teams[team][getn(teams[team])+1]={kills=val.score,ping=val.ping,deaths=val.deaths,ready=val.ready,entity=ent, pclass=ent.sCurrentPlayerClass};
  162.                 end
  163.             end
  164.         end
  165.         
  166.                         
  167.         local playersCount=max(count(teams.blue),count(teams.red));
  168.         local spectatorsCount=count(teams.spectators);
  169.  
  170.         local yScale=1;                
  171.         if(playersCount+spectatorsCount>22) then
  172.             yScale=22/(playersCount+spectatorsCount);
  173.         end        
  174.         
  175.         -- always center scoreboard...
  176.         local ypos=300-(((playersCount+spectatorsCount)+3)*21)*0.5*yScale;        
  177.         
  178.         local ysize=(playersCount+1)*21*yScale;
  179.         
  180.         ScoreBoardManager:RenderTeamWindow(56, ypos-10*yScale, playersCount, spectatorsCount, 0, 0, 1, 1.34, yScale);
  181.         ScoreBoardManager:RenderTeamWindow(400, ypos-10*yScale, playersCount, spectatorsCount, 1, 0, 0, 1.34, yScale);
  182.                     
  183.         local bluepos=self:RenderTeam(teams.blue, Game:GetTeamScore("blue"), 56, ypos, 344, ysize, {0,0,1,0.3}, nil, bclass, yScale);
  184.         local redpos=self:RenderTeam(teams.red, Game:GetTeamScore("red"), 400, ypos, 344, ysize, {1,0,0,0.3}, nil, bclass, yScale);
  185.         
  186.         -- always increase size to fit..
  187.         if(playersCount>=1) then
  188.             ysize=ysize+10*yScale;                        
  189.             ypos=ypos+ysize;
  190.         else
  191.             ypos=ypos+32*yScale;
  192.         end
  193.         
  194.         self:RenderTeam(teams.spectators, 0, 56, ypos, 688, ysize, nil, 1, bclass, yScale);
  195.         
  196.     end
  197. end
  198.  
  199. -- render team display window
  200. function ScoreBoardManager:RenderTeamWindow(xpos, ypos, playersCount, spectatorsCount, r, g, b, xScale, yScale)
  201.     local x, y, plCount, specCount=xpos, ypos, playersCount, spectatorsCount;
  202.         
  203.     -- render red team menu
  204.     Hud:DrawScoreBoard(x, y, xScale, 0.45*yScale, 100, Hud.tmpscoreboard.bar_score, r, g, b, 1, 0, 0);        
  205.     y=y+31*yScale;
  206.     
  207.     Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_info, 1, 1, 1, 1, 0, 0);
  208.     y=y+21*yScale;
  209.     
  210.     while plCount>0 do                    
  211.         Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_player, 1, 1, 1, 1, 0, 0);
  212.         y=y+21*yScale;
  213.         plCount=plCount-1;
  214.     end
  215.     
  216.     while specCount>0 do                            
  217.         Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_player, 1, 1, 1, 1, 0, 0);
  218.         y=y+21*yScale;
  219.         specCount=specCount-1;
  220.     end
  221.     
  222.     Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_bottom, 1, 1, 1, 1, 0, 0);
  223. end
  224.  
  225. -------------------------------------------------------------------------------
  226. --CLASSIC INDIVIDUAL GAME (DM etc...)
  227. -------------------------------------------------------------------------------
  228. function ScoreBoardManager:RenderDMGame()
  229.  
  230.     Game:SetHUDFont("default", "scoreboard");
  231.     
  232.     local header_textsize = 16;
  233.     local body_textsize = 14;
  234.     
  235.     local deathsfieldsize = Game:GetHudStringSize("DEATHS", header_textsize, header_textsize);
  236.     local pingfieldsize = Game:GetHudStringSize("PING", header_textsize, header_textsize);
  237.     local killsfieldsize = Game:GetHudStringSize("KILLS", header_textsize, header_textsize);
  238.     
  239.     if(self.visible==1)then
  240.         local players={}
  241.         local spectators={}
  242.         
  243.         for id, val in ScoreBoardManager.scores do
  244.             --RENDER PLAYERS
  245.             local ent = System:GetEntity(val.id);
  246.             if(ent)then
  247.                 if (ent.classname=="Player") then
  248.                     players[getn(players)+1]={kills=val.score,ping=val.ping,deaths=val.deaths,ready=val.ready,entity=ent};
  249.                 elseif (ent.classname=="Spectator") then
  250.                     spectators[getn(spectators)+1]={kills=val.score,ping=val.ping,deaths=val.deaths,ready=val.ready,entity=ent};
  251.                 end
  252.             end
  253.         end
  254.     
  255.         if(count(players)>1)then
  256.             sort(players,%player_compare);
  257.         end
  258.         
  259.     --RENDER + HERE
  260.         
  261.         local playersCount=count(players);
  262.         local spectatorsCount=count(spectators);
  263.  
  264.         local yScale=1;                
  265.         if(playersCount+spectatorsCount>22) then
  266.             yScale=22/(playersCount+spectatorsCount);
  267.         end        
  268.         
  269.         -- always center scoreboard...
  270.         local ypos=300-(((playersCount+spectatorsCount)+3)*21)*0.5*yScale;                
  271.         local ysize=(playersCount+1)*21*yScale;
  272.         
  273.         ScoreBoardManager:RenderTeamWindow(190, ypos-10*yScale, playersCount, spectatorsCount, 0, 0, 1, 1.65, yScale);        
  274.         
  275.         local xpos=200;
  276.         --local ypos=100;
  277.         local xsize=400;
  278.         local tpos=ypos;        
  279.         
  280.         Game:WriteHudString( xpos, tpos, "$6PLAYER", 1, 1, 1, 1, header_textsize, header_textsize);
  281.         Game:WriteHudString( xpos+(xsize-132), tpos, "$6DEATHS", 1, 1, 1, 1, header_textsize, header_textsize);
  282.         Game:WriteHudString( xpos+(xsize-76), tpos, "$6PING", 1, 1, 1, 1, header_textsize, header_textsize);
  283.         Game:WriteHudString( xpos+(xsize-38), tpos, "$6KILLS", 1, 1, 1, 1, header_textsize, header_textsize);
  284.         tpos=tpos+21*2+5 ;
  285.         --PLAYERS
  286.  
  287.         for id, val in players do
  288.             --RENDER PLAYERS
  289.             local ent = val.entity;
  290.             if(ent)then
  291.  
  292.                 if(ent==_localplayer and i ~= 1)then
  293.                     --%System:DrawImageColor(self.white_dot, xpos, tpos, xsize, 24, 4,0.1,0.1,0.1,0.75);
  294.                 end
  295.                 
  296.                 local deathssize = Game:GetHudStringSize(val.deaths, body_textsize, body_textsize);
  297.                 local pingsize = Game:GetHudStringSize(val.ping, body_textsize, body_textsize);
  298.                 local killssize = Game:GetHudStringSize(val.kills, body_textsize, body_textsize);
  299.                 
  300.                 local deathsx = xpos+(xsize-132) + (deathsfieldsize - deathssize) * 0.5;
  301.                 local pingx = xpos+(xsize-76) + (pingfieldsize - pingsize) * 0.5;
  302.                 local killsx = xpos+(xsize-38) + (killsfieldsize - killssize) * 0.5;
  303.                 
  304.                 --tpos = tpos + 4;
  305.  
  306.                 Game:WriteHudString( xpos+5, tpos, ent:GetName(), 1, 1, 1, 1, body_textsize, body_textsize);
  307.                 Game:WriteHudString( deathsx, tpos, "$1"..val.deaths, 1, 1, 1, 1, body_textsize, body_textsize);
  308.                 Game:WriteHudString( pingx, tpos, "$1"..val.ping, 1, 1, 1, 1, body_textsize, body_textsize);
  309.                 Game:WriteHudString( killsx, tpos, "$1"..val.kills, 1, 1, 1, 1, body_textsize, body_textsize);
  310.                 
  311.                 tpos=tpos+21;
  312.             end
  313.         end
  314.         
  315.         --tpos = tpos + 2;
  316.         
  317.         --SPECTATORS
  318.         for id, val in spectators do
  319.  
  320.             local ent = val.entity;
  321.             
  322.             if (ent) then
  323.                 --RENDER SPECTATORS
  324.                 if(ent==_localplayer)then
  325.                     --%System:DrawImageColor(self.white_dot, xpos, tpos, xsize, 24, 4,0.1,0.1,0.1,0.75);
  326.                 end
  327.                 
  328.                 --tpos = tpos + 4;
  329.                 
  330.                 Game:WriteHudString( xpos+6, tpos, ent:GetName(), 1, 1, 1, 1, body_textsize, body_textsize);
  331.                 Game:WriteHudString( xpos+(xsize-74), tpos, "$6SPECTATOR", 1, 1, 1, 1, body_textsize, body_textsize);
  332.                 --Game:WriteHudString( xpos+(xsize-190), tpos, "$1"..val.deaths, 1, 1, 1, 1, body_textsize, body_textsize);
  333.                 --Game:WriteHudString( xpos+(xsize-130), tpos, "$1"..val.ping, 1, 1, 1, 1, body_textsize, body_textsize);
  334.                 tpos=tpos+21;
  335.             end
  336.         end
  337.     end
  338. end
  339.  
  340. function ReloadScoreBoard()
  341.     --System:Log("\001Reloading Scoreboard...");
  342.     Script:ReloadScript("SCRIPTS/Multiplayer/TDMscoreboard.lua");    
  343.     Script:ReloadScript("SCRIPTS/Assault/Hud/scoreboard.lua");    
  344. end
  345.  
  346. Input:BindCommandToKey("#ReloadScoreBoard()","f5",1);